package com.ziyun.erp.web.modules.supp.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.supp.entity.SupplierRemarksEntity;
import com.ziyun.erp.modules.supp.service.SupplierRemarksService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 供应商（工厂）备注表
 *
 * @author gaosheng
 * @email 
 * @date 2018-09-06 17:16:14
 */
@RestController
@RequestMapping("supp/supplierremarks")
public class SupplierRemarksController {
    @Autowired
    private SupplierRemarksService supplierRemarksService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("supp:supplierremarks:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = supplierRemarksService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{srId}")
    @RequiresPermissions("supp:supplierremarks:info")
    public R info(@PathVariable("srId") Integer srId){
        SupplierRemarksEntity supplierRemarks = supplierRemarksService.selectById(srId);

        return R.ok().put("supplierRemarks", supplierRemarks);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("supp:supplierremarks:save")
    public R save(@RequestBody SupplierRemarksEntity supplierRemarks){
        supplierRemarksService.insert(supplierRemarks);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("supp:supplierremarks:update")
    public R update(@RequestBody SupplierRemarksEntity supplierRemarks){
        ValidatorUtils.validateEntity(supplierRemarks);
        supplierRemarksService.updateAllColumnById(supplierRemarks);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("supp:supplierremarks:delete")
    public R delete(@RequestBody Integer[] srIds){
        supplierRemarksService.deleteBatchIds(Arrays.asList(srIds));

        return R.ok();
    }

    /**
     * 查询备注
     * @param srSupplierId
     * @return
     */
    @RequestMapping("/remarks")
    public R remarks(@RequestParam(value = "srSupplierId") Integer srSupplierId){
        List<SupplierRemarksEntity> supplierRemarksEntities = supplierRemarksService.selectList(new EntityWrapper<>(
                new SupplierRemarksEntity()).where("sr_supplier_id = {0}", srSupplierId)
        );
        return R.ok().put("list", supplierRemarksEntities);
    }

}
